﻿using System.Windows;

namespace SHomeWorkshop.LunarPresentation.Commands
{
    public partial class Command
    {
        public static void Merge(MergeOperation mergeOperation)
        {
            if (Globals.selectedEditor == null) return;
            if (Globals.selectedEditor.SelectedExpression == null) return;

            LunarPresentation.Expressions.Expression curEx
                = Globals.selectedEditor.SelectedExpression;

            if ((curEx is Expressions.GridPanel) == false)
            {
                if (curEx.ParentPanel is Expressions.GridPanel)
                {
                    curEx = curEx.ParentPanel;
                }
                else
                {
                    MessageBox.Show("请先选中一个网格子面板，然后再执行此一操作。",
                        Globals.appName,
                        MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;//只有网格式子面板或其子级公式才能进行操作。
                }
            }

            Expressions.GridPanel gp = curEx as Expressions.GridPanel;

            switch (mergeOperation)
            {
                case MergeOperation.Bottom:
                    {
                        gp.MergeBottom(); break;
                    }
                case MergeOperation.Right:
                    {
                        gp.MergeRight(); break;
                    }
                default:
                    {
                        gp.MergeCancel(); break;
                    }
            }
        }

        public enum MergeOperation { Right, Bottom, Cancel }
    }
}
